<template>
  <div id="tt">
    <div>{{ drag ? "拖拽中" : "拖拽停止" }}</div>
    <vuedraggable
      v-model="myArray"
      chosen-class="chosen"
      ghost-class="glost"
      group="people"
      animation="500"
      :force-fallback="true"
      @start="onStart"
      @end="onEnd"
    >
      <transition-group>
        <div class="item" v-for="element in myArray" :key="element.id">
          {{ element.name }}
        </div>
      </transition-group>
    </vuedraggable>
    <div style="margin-top:30px;">
      {{ JSON.stringify(myArray)}}
    </div>
  </div>
</template>

<script>
import vuedraggable from 'vuedraggable'
export default {
  components: { vuedraggable },
  data() {
    return {
      drag: false,
      myArray: [
        { people: 'cn', id: 1, name: 'www.itxst.com' },
        { people: 'cn', id: 2, name: 'www.baidu.com' },
        { people: 'cn', id: 3, name: 'www.taobao.com' },
        { people: 'us', id: 4, name: 'www.google.com' }
      ]
    }
  },
  methods: {
    onStart() {
      this.drag = true
    },
    onEnd() {
      this.drag = false
    }
  }
}
</script>

<style scoped>
.item {
  padding: 6px;
  background-color: #fdfdfd;
  border: solid 1px #eee;
  margin-bottom: 10px;
  cursor: move;
}

.item:hover {
    background-color: #f1f1f1;
    cursor: move;
}

.chosen {
  border: solid 2px #3089dc !important;
  background-color:burlywood!important;
}
.glost {
  background-color:aqua;
}

</style>
